package com.yanqu.road.server.cmd.activity.feast;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ShanHeFeastProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.feast.ShanHeFeastModule;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.S_SHAN_HE_FEAST_SET_IMAGE, desc = "凡人设置形象")
public class FeastImageSetCmd extends AbstractCommand {

	private Integer activityId;
	private int imageId;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		ShanHeFeastProto.FeastImageSetReqMsg reqMsg = ShanHeFeastProto.FeastImageSetReqMsg.parseFrom(packet.getBytes());
		activityId = reqMsg.getActivityId();
		imageId = reqMsg.getImageId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(ShanHeFeastModule.class).imageSet(activityId, imageId);
	}

	@Override
	public void sendData(GamePlayer player) {
		if(ret != 0){
			ShanHeFeastProto.FeastSetImageRespMsg.Builder builder = ShanHeFeastProto.FeastSetImageRespMsg.newBuilder();
			builder.setRet(ret);
			player.sendPacket(Protocol.U_SHAN_HE_FEAST_SET_IMAGE, builder);
		}
	}
}